﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;

namespace DAL
{
    public class ProductDAL
    {
        /// <summary>
        /// 查询显示
        /// </summary>
        /// <returns></returns>
        public static DataTable dat() {
            string ss = "select * from ProductInfo";
            DataTable da = DB.GetTable(ss);
            return da;
        }
        /// <summary>
        /// ProductInfo条件删除的封装
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool S(int id) {
            string ss = "DELETE FROM [dbo].[ProductInfo]WHERE Pid=" + id;
            return DB.ZSG(ss);
        }
        /// <summary>
        /// Productclass查询商品类型
        /// </summary>
        /// <returns></returns>
        public static DataTable GetData() {
            string ss = "select * from Productclass";
            DataTable dat = DB.GetTable(ss);
            return dat;
        }
        /// <summary>
        /// ProductInfo增加数据
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static bool ins(Product p) {
            string ss = string.Format("INSERT INTO [dbo].[ProductInfo]([PName],[PClass] ,[PImg],[PPrice]) VALUES('{0}','{1}','{2}','{3}')",p.PName,p.PClass,p.PImg,p.PPrice);
            return DB.ZSG(ss);
        }
        /// <summary>
        /// productinfo修改填充的语句封装
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static Product p(string s) {
            string ss = "select * from productinfo where pid=" + s;
            DataTable dat = DB.GetTable(ss);
            if (dat != null && dat.Rows.Count > 0)
            {
                Product pro = new Product() {
                    PID = Convert.ToInt16(dat.Rows[0]["pid"]),
                    PName = dat.Rows[0]["Pname"] + "",
                    PClass = dat.Rows[0]["PClass"] + "",
                    PImg = dat.Rows[0]["PImg"] + "",
                    PPrice =
                   Convert.ToInt16( dat.Rows[0]["pprice"])
               
                };
                return pro;
            }
            else
            {
                return null;
            }
            
        }
        /// <summary>
        /// ProductInfo 的修改Sql语句封装
        /// </summary>
        /// <param name="p"></param>
        /// <param name="s"></param>
        /// <returns></returns>
        public static bool Update(Product p ,int s) {
            string ss = string.Format("UPDATE [dbo].[ProductInfo]SET [PName] ='{0}' ,[PClass] ='{1}' ,[PImg] = '{2}',pprice = '{3}' WHERE pid='{4}'",p.PName,p.PClass,p.PImg,p.PPrice,s);
            return DB.ZSG(ss);
        }
    }
}
